package FB数列;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int f0 = 0, f1 = 1, f2 = 1, res = 0;
        int n = in.nextInt();
        while (true) {
            if (f2 >= n) {
                res = Math.min(f2 - n, n - f1);
                break;
            }
            f0 = f1;
            f1 = f2;
            f2 = f0 + f1;
        }
        System.out.println(res);
    }
}
